export default {
	// 判断是否为微信环境
	isWechat: () => {
		var ua = navigator.userAgent.toLowerCase();
		var isWXWork = ua.match(/wxwork/i) == 'wxwork';
		var isWeixin = !isWXWork && ua.match(/MicroMessenger/i) == 'micromessenger';
		return isWeixin;
	},

	// 获取code并登录   
	getWXCode: async (url, snsapi, appid) => {
		// let appid = 'wx73df522034ec74f8' //公众号的唯一标识
		let local = encodeURIComponent(url); //授权后重定向的回调链接地址
		// let local = encodeURIComponent('https://yao.tanfan.cc/addons/duanju/#/')
		let time = +new Date(); //时间戳
		window.location.href =
			`https://open.weixin.qq.com/connect/oauth2/authorize?
				appid=${appid}&
				redirect_uri=${local}&
				response_type=code&
				scope=${snsapi}&
				state=1&
				time=${time}#wechat_redirect`;
	},
	// 截取code
	getUrlParam: (name) => {
		let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		let r = window.location.search.substr(1).match(reg);
		if (r != null) {
			return unescape(r[2]);
		}
		return null;
	},
	

}